package com.boot2.core.conf;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.CollectionUtils;

import javax.sql.DataSource;
import java.util.Map;

/**
* @author zhangweilin
* @date 2018/7/4 16:58 
* @description:  走事务的条件配置
*/
public class TxConditional implements Condition{

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        Map<String, DataSource> dataSourceMap = conditionContext.getBeanFactory().getBeansOfType(DataSource.class);
        if (CollectionUtils.isEmpty(dataSourceMap)) {
            return false;
        }
        return true;
    }
}